package com.greenx.hello;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * @author Stephen Xianwei Zhang
 * 
 */
public class HReg {

	private static Pattern validVINPattern = Pattern
			.compile("^[a-zA-Z0-9]{17}$");

	public static void main(String[] args) {
		boolean flag = HReg.checkSpecialChar("sdkjf234sadAkjf");
		System.out.println(flag);
		flag = HReg.checkSpecialChar("sd/kjf234sadAkjf");
		System.out.println(flag);
	}

	/**
	 * VIN only can has a-z or A-Z or 0-9
	 * 
	 * @param vin
	 *            to be checked
	 * @return true means VIN is okay; false means it contains special char
	 */
	public final static boolean checkSpecialChar(String str) {
		boolean hasSpecial = true;
		Pattern normalPattern = Pattern.compile("[a-zA-Z0-9]*");
		Matcher mathcer = normalPattern.matcher(str);
		validVINPattern.matcher(str);
		hasSpecial = mathcer.matches();
		return hasSpecial;
	}

}
